package com.elmcode.server.controller.app;


import com.elmcode.server.dto.CustomerSaveInfo;
import com.elmcode.server.exception.ParamsException;
import com.elmcode.server.exception.UserException;
import com.elmcode.server.service.CustomerService;
import com.elmcode.server.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "顾客接口")
@RestController
@RequestMapping("app/customer")
public class CustomerController {



    @Autowired
    private CustomerService customerService;


    /**
     * 顾客登录
     * /admin/user/login
     */
    @ApiOperation("顾客登录接口")
    @PostMapping("/login")
    public Result login(String phone, String password) throws ParamsException {

        Map<String,Object> data = customerService.login(phone,password);

        return Result.ok("登录成功",data);
    }

    /**
     * 添加顾客
     */
    @ApiOperation("添加顾客接口")
    @PostMapping
    public Result addUser(CustomerSaveInfo customerSaveInfo) throws UserException {
        customerService.saveCustomer(customerSaveInfo);
        return Result.ok("添加成功");
    }


}
